package com.zc.commons.context;

import com.zc.commons.pojo.AuthenticatedUser;

/**
 * 全局用户认证信息
 */
public class AuthenticationContext {

    private static final ThreadLocal<AuthenticatedUser> contextUser = new ThreadLocal<>();

    public static AuthenticatedUser getCurrentUser() {

        AuthenticatedUser user = contextUser.get();
        if (user == null) {
            user = new AuthenticatedUser();
            contextUser.set(user);
        }
        return user;

    }

    public static void setContextUser(AuthenticatedUser user) {
        contextUser.set(user);
    }

    public static void clear() {
        contextUser.remove();
    }


}
